package util;

import java.util.LinkedList;

public class Order {
	private int orderId;
	private String stock;
	private String orderType;
	private float price;
	private int amount;
	private int left;
	private String orderStatus = "new";
	private LinkedList<FillReport> fillList;
	
	public Order(int orderId, String stock, String orderType, float price, int amount) {
		this.orderId = orderId;
		this.stock = stock;
		this.orderType = orderType;
		this.price = price;
		this.amount = amount;
		this.left = amount;
		fillList = new LinkedList<FillReport>();
	}

	
	public void addReport(FillReport report){
		left -= report.getAmount();
		orderStatus = (left == 0) ? "filled" : "partially filled";
		fillList.add(report);
	}

	@Override
	public String toString() {
		return ("id " + orderId +
				" Stock: " + stock + " OrderType " + orderType +
				" Price: " + price + " Amount: " + amount + " (" + left + ")" +
				" Status: " + orderStatus + printFillList() );
	}
	
	private String printFillList() {
		StringBuilder strBldr = new StringBuilder(" by: ");
		for (FillReport report : fillList){
			strBldr.append(report.toString() );
		}
		return strBldr.toString();
	}

	public int getOrderId() {
		return orderId;
	}

	public String getStock() {
		return stock;
	}
	
	public String getOrderType() {
		return orderType;
	}

	public float getPrice() {
		return price;
	}

	public int getAmount() {
		return amount;
	}


	public void setOrderStatus(String status) {
		this.orderStatus = status;
	}


}
